//
// Created by xunx on 2018/12/8.
//

#include "Vertices.h"

Vertices::Vertices() {
    Init();
}

void Vertices::Init() {
    float vertices[] = {
            // positions    // texture
            1.0f, 1.0f, 1.0f, 1.0f,  // top right
            1.0f, 0.0f, 1.0f, 0.0f,  // bottom right
            0.0f, 0.0f, 0.0f, 0.0f,  // bottom left
            0.0f, 1.0f, 0.0f, 1.0f   // top left
    };
    unsigned int indices[] = {
            0, 1, 3,
            1, 2, 3
    };
    unsigned int VBO, EBO;
    glGenVertexArrays(1, &VAO);
    glGenBuffers(1, &VBO);
    glGenBuffers(1, &EBO);

    glBindVertexArray(VAO);

    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*) 0);
    glEnableVertexAttribArray(0);

    glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*) (2 * sizeof(float)));
    glEnableVertexAttribArray(1);
}

unsigned int Vertices::GetVAO() {
    return VAO;
}


